package com.tfswue.springboot_demo02.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tfswue.springboot_demo02.entity.User;
import com.tfswue.springboot_demo02.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/getUser")
    public User getUser(){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 1);
/*        queryWrapper.eq("username", "t");*/
        List<User> list = userService.list(queryWrapper);
        return userService.getById(1);
    }

    // 查询所有用户
    @RequestMapping("/user/list")
    public List<User> list() {
        return userService.list();
    }

    // 根据id查询用户
    @RequestMapping("/user/get")
    public User getById(Integer id) {
        return userService.getById(id);
    }

    // 新增用户
    @RequestMapping("/user/add")
    public boolean add(User user) {
        return userService.save(user);
    }

    // 修改用户
    @RequestMapping("/user/update")
    public boolean update(User user) {
        return userService.updateById(user);
    }

    // 删除用户
    @RequestMapping("/user/delete")
    public boolean delete(Integer id) {
        return userService.removeById(id);
    }
}